package com.lijian.search.controller;

import java.io.UnsupportedEncodingException;

import org.aspectj.weaver.AjAttribute.PrivilegedAttribute;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.lijian.common.utils.TaotaoResult;
import com.lijian.search.pojo.SearchResult;
import com.lijian.search.service.impl.SearchService;

/**
 * <p>Title: SearchController.java</p>
 * <p>Description: </p>
 * <p>Copyright: Copyright (c) 2017</p>
 * @author lijian
 * @date 2017年4月16日下午10:10:29
 * @version 1.0
 */
@Controller
public class SearchController {
	@Autowired
	private SearchService searchService;
	
	@RequestMapping("/q")
	@ResponseBody
	public TaotaoResult query(@RequestParam(defaultValue="")String keyword,@RequestParam(defaultValue="1")Integer page,@RequestParam(defaultValue="30")Integer rows){
		try {
			keyword=new String(keyword.getBytes("iso-8859-1"),"utf-8");
		} catch (UnsupportedEncodingException e) {
			e.printStackTrace();
		}
		SearchResult search = searchService.search(keyword, page, rows);
		return TaotaoResult.ok(search);
	}

}
